class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

class Solution:
    def isSubStructure(self, A: TreeNode, B: TreeNode) -> bool:
        if A is None or B is None:
            return False

        # 当前节点
        if self.dfs(A, B):return True

        #左节点
        if self.isSubStructure(A.left, B): return True

        #右节点
        if self.isSubStructure(A.right, B): return True

        return False

    

    def dfs(self,  A:TreeNode,  B:TreeNode):
        if B is None: return True
        if A is None: return False
        if A.val != B.val: return False

        return self.dfs(A.left, B.left) and self.dfs(A.right, B.right)

